package com.atguigu.gmall.payment.pay;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: atguigu
 * @create: 2023-05-10 14:45
 */
@Component
public class PayManager {


    //@Autowired
    //private WxPayWay wxPayWay;

    //@Autowired
    //private AlipayWay alipayWay;

    /**
     * 注入所有的支持支付平台对象
     * Map中Key:支付对象Bean对象ID
     * Map中Value:支付实例对象
     */
    @Autowired
    private Map<String, PayAPI> payWayMap;

    /**
     * 根据前端提交支付类比,返回支付实例对象
     * @param type 页面中提交选择支付方式
     */
    public PayAPI getPayInstance(String type) {
        PayAPI payAPI = payWayMap.get(type);
        if (payAPI == null) {
            throw new RuntimeException("暂不支持该支付方式");
        }
        return payAPI;
    }
}
